<?php

/* ============================================
    拡張子を捜す
   ============================================ */
if (!function_exists('fFindExt')) {
    function fFindExt($sPath,$sPatMatch=null){
        if( !(preg_match('/[\/]+/',strtolower($sPath))) ){
            $sParse = $sPath;
        }
        else if(preg_match('/^http/',strtolower($sPath))){
            $aParse = parse_url($sPath);
            $sParse = $aParse['path'];
        }
        else{
            //とりあえず相対パスかのチェックの為に絶対パスに変換
            $sPath_temp = realpath($sPath);
            if(!Empty($sPath_temp)){
                $sPath = $sPath_temp;
            }
        }

        if(preg_match('/^[\/]/',strtolower($sPath))){
            $aParse = parse_url($sPath);
            $sParse = $aParse['path'];
        }

        $aExt = explode('.',$sParse);
        $sExt = strtolower($aExt[count($aExt)-1]);

        $sPatMatch = (Empty($sPatMatch)) ? '/^(gif|png|jpe?g)$/' : $sPatMatch;
        if (preg_match($sPatMatch,$sExt)) {
            return $sExt;
        }
        else{
            return "{$sExt}_invalid";
        }
    }
}

?>